package com.chat.room;

import com.chat.room.common.CommonConstant;
import com.chat.room.common.ServiceConstant;
import com.chat.room.service.ChatRoomServerListener;
import com.chat.room.service.SearchListener;
import lombok.extern.slf4j.Slf4j;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramSocket;
import java.net.SocketException;

@Slf4j
public class ServiceRun {

    public static void main(String[] args) throws SocketException {
        SearchListener searchListener = new SearchListener(new DatagramSocket(CommonConstant.SEARCH_PORT), true);
        ServiceConstant.THREAD_POOL_EXECUTOR.execute(searchListener);

        ChatRoomServerListener chatRoomServerListener = new ChatRoomServerListener();
        try {
            chatRoomServerListener.listener();
        } catch (IOException e) {
            log.error("聊天室服务器监听异常：{}",e);
        }

        try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));) {
            bufferedReader.readLine();
        } catch (IOException e) {
            log.error("异常:{}", e);
        }

        searchListener.close();
    }
}